<template>
    <div class="public_head">
        <ul>
            <li @click="openDg(1)">
                <p><span>*</span>关联AR地标</p>
                <el-input v-model="landmarkNames" placeholder="请选择AR地标" maxlength="50" type="text" class="headInput" :readonly="true" />
            </li>
            <li @click="openDg(2)">
                <p><span>*</span>关联U3D物品</p>
                <el-input v-model="u3dName" placeholder="请输入U3D中对应物品的识别参数" maxlength="50" type="text" class="headInput" :readonly="true"/>
            </li>
        </ul>
        
            <my-dialog v-if="lkFlag" :show.sync="lkFlag" :showBtn="dataType==1" width="500px" :title="dataType==1?'关联AR地标':'关联U3D物品'" @confirm="getSelectData">
                
                <my-table v-if="dataType==1" :loading="loading" :lists="tableData" @selectionChange="tableSelect" @pageChange="handleChange" :showCheck="true" :sequence="true" :page='page' selectKey="arLandmarkId|name">
                    <el-table-column property="arLandmarkId" label="地标ID" align='left'></el-table-column>
                    <el-table-column property="name" label="地标名称" align='center'></el-table-column>
                </my-table>

                <my-table v-else-if="dataType==2" :loading="loading" :lists="tableData" @pageChange="handleChange" :sequence="true" :page='page'>
                    <el-table-column property="arObjectId" label="物品id" align='left'></el-table-column>
                    <el-table-column property="objectName" label="物品名称" align='center'></el-table-column>
                    <el-table-column property="objectType" label="物品类型" align='center'></el-table-column>
                    <el-table-column prop="status" label="操作" align="center" width="100px">
                        <template slot-scope="scope">
                            <el-button size="mini" type="success" plain @click="selectu3d(scope.row)">选择</el-button>
                        </template>
                    </el-table-column>
                </my-table>

            </my-dialog> 

        
    </div>
</template>

<script>
import {mapGetters} from 'vuex'
import {
  getLandmarkList,
  getArobjectList
} from '@/api/arApi'
import myDialog from '@/components/public/myDialog';
import myTable from '@/components/public/myTable';
export default {
    components:{
        myDialog,
        myTable
    },
    data(){
        return{
            landmarkNames:'',
            u3dName:'',
            lkFlag:false,
            page:{
                pageSize:10,
                pageIndex:1,
			    total:0,
            },
            loading:true,
            tableData:[],
            multipleSelectionIds:[],
            dataType:1
        }
    },
    computed:{
        ...mapGetters({
            'goodsAddParams':'goods/goodsAddParams'
        })
    },
    created(){
        
    },
    methods:{
        openDg(num){
            this.dataType = num
            this.lkFlag=true
            this.page.pageIndex = 1;
            this.tableData=[]
            this.getList()
        },
        async getList(){
            const params = {
                limit: this.page.pageSize,
                page: this.page.pageIndex
            }
            let res = ''
            if(this.dataType==1){
                res = await getLandmarkList(params)  // 获取地标
            }else if(this.dataType==2){
                res = await getArobjectList(params) // 获取u3d物品
            }

            this.loading = false
            this.tableData = res.data
            this.page.total = res.total
            
        },
        getSelectData(){
            this.lkFlag = false
        },
        tableSelect(obj,items){
            this.$store.commit('goods/set_arLandmark',{
                arLandmarkIds:obj.arLandmarkId,
                name:obj.name
            })
            
            this.landmarkNames = obj.name.join(',')
        },
        handleChange(index) {
            this.page.pageIndex = index;
            this.getList();
        },
        selectu3d(item){
            this.$store.commit('goods/set_u3d',{
                arObjectId:item.arObjectId,
                objectName:item.objectName
            })
            this.u3dName = item.objectName
            this.lkFlag = false
        }
    }
}
</script>

<style lang="scss" scoped>
    .public_head {
            ul {
                padding: 0;
                display: flex;
                flex-wrap: wrap;
                padding: 30px 50px 10px 84px;
                box-sizing: border-box;
                margin: 0;
                li {
                    display: flex;
                    width: 50%;
                    margin-bottom: 20px;
                    align-items: center;
                    p {
                        width: 120px;
                        span {
                            color: #ff0000;
                        }
                    }
                    .headInput {
                        width: 400px;
                    }
                }
            }
        }
</style>